package com.github.catvod.spider.merge;

import com.github.catvod.spider.merge.HZ;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;

/* loaded from: classes.dex */
public class QF implements Iterable<tF>, Cloneable {
    private int h = 0;
    String[] V0 = new String[3];
    String[] j = new String[3];

    class Tw implements Iterator<tF> {
        int h = 0;

        Tw() {
        }

        @Override // java.util.Iterator
        /* renamed from: h, reason: merged with bridge method [inline-methods] */
        public tF next() {
            QF qf = QF.this;
            String[] strArr = qf.V0;
            int i = this.h;
            tF tFVar = new tF(strArr[i], qf.j[i], qf);
            this.h++;
            return tFVar;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            while (this.h < QF.this.h) {
                QF qf = QF.this;
                if (!qf.GM(qf.V0[this.h])) {
                    break;
                }
                this.h++;
            }
            return this.h < QF.this.h;
        }

        @Override // java.util.Iterator
        public void remove() {
            QF qf = QF.this;
            int i = this.h - 1;
            this.h = i;
            qf.Og(i);
        }
    }

    private void BQ(int i) {
        R2.j(i >= this.h);
        String[] strArr = this.V0;
        int length = strArr.length;
        if (length >= i) {
            return;
        }
        int i2 = length >= 3 ? this.h * 2 : 3;
        if (i <= i2) {
            i = i2;
        }
        this.V0 = (String[]) Arrays.copyOf(strArr, i);
        this.j = (String[]) Arrays.copyOf(this.j, i);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean GM(String str) {
        return str != null && str.length() > 1 && str.charAt(0) == '/';
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void Og(int i) {
        R2.V0(i >= this.h);
        int i2 = (this.h - i) - 1;
        if (i2 > 0) {
            String[] strArr = this.V0;
            int i3 = i + 1;
            System.arraycopy(strArr, i3, strArr, i, i2);
            String[] strArr2 = this.j;
            System.arraycopy(strArr2, i3, strArr2, i, i2);
        }
        int i4 = this.h - 1;
        this.h = i4;
        this.V0[i4] = null;
        this.j[i4] = null;
    }

    private int PD(String str) {
        R2.u(str);
        for (int i = 0; i < this.h; i++) {
            if (str.equalsIgnoreCase(this.V0[i])) {
                return i;
            }
        }
        return -1;
    }

    static String W(@Nullable String str) {
        return str == null ? "" : str;
    }

    static String j5(String str) {
        return '/' + str;
    }

    public String F8(String str) {
        int PD = PD(str);
        return PD == -1 ? "" : W(this.j[PD]);
    }

    public void I(QF qf) {
        if (qf.size() == 0) {
            return;
        }
        BQ(this.h + qf.h);
        Iterator<tF> it = qf.iterator();
        while (it.hasNext()) {
            w4(it.next());
        }
    }

    void LW(String str, @Nullable String str2) {
        int PD = PD(str);
        if (PD == -1) {
            q(str, str2);
            return;
        }
        this.j[PD] = str2;
        if (this.V0[PD].equals(str)) {
            return;
        }
        this.V0[PD] = str;
    }

    public void PU() {
        for (int i = 0; i < this.h; i++) {
            String[] strArr = this.V0;
            strArr[i] = AR.h(strArr[i]);
        }
    }

    public int Qy(Qg qg) {
        int i = 0;
        if (isEmpty()) {
            return 0;
        }
        boolean q = qg.q();
        int i2 = 0;
        while (i < this.V0.length) {
            int i3 = i + 1;
            int i4 = i3;
            while (true) {
                Object[] objArr = this.V0;
                if (i4 < objArr.length && objArr[i4] != null) {
                    if (!q || !objArr[i].equals(objArr[i4])) {
                        if (!q) {
                            String[] strArr = this.V0;
                            if (!strArr[i].equalsIgnoreCase(strArr[i4])) {
                            }
                        }
                        i4++;
                    }
                    i2++;
                    Og(i4);
                    i4--;
                    i4++;
                }
            }
            i = i3;
        }
        return i2;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || QF.class != obj.getClass()) {
            return false;
        }
        QF qf = (QF) obj;
        if (this.h == qf.h && Arrays.equals(this.V0, qf.V0)) {
            return Arrays.equals(this.j, qf.j);
        }
        return false;
    }

    public int hashCode() {
        return (((this.h * 31) + Arrays.hashCode(this.V0)) * 31) + Arrays.hashCode(this.j);
    }

    final void i4(Appendable appendable, HZ.Tw tw) {
        int i = this.h;
        for (int i2 = 0; i2 < i; i2++) {
            if (!GM(this.V0[i2])) {
                String str = this.V0[i2];
                String str2 = this.j[i2];
                appendable.append(' ').append(str);
                if (!tF.u(str, str2, tw)) {
                    appendable.append("=\"");
                    if (str2 == null) {
                        str2 = "";
                    }
                    XR.I(appendable, str2, tw, true, false, false);
                    appendable.append('\"');
                }
            }
        }
    }

    public String iU() {
        StringBuilder V0 = ZG.V0();
        try {
            i4(V0, new HZ("").TD());
            return ZG.t(V0);
        } catch (IOException e) {
            throw new zx(e);
        }
    }

    public boolean isEmpty() {
        return this.h == 0;
    }

    @Override // java.lang.Iterable
    public Iterator<tF> iterator() {
        return new Tw();
    }

    public boolean n(String str) {
        return PD(str) != -1;
    }

    public List<tF> oC() {
        ArrayList arrayList = new ArrayList(this.h);
        for (int i = 0; i < this.h; i++) {
            if (!GM(this.V0[i])) {
                arrayList.add(new tF(this.V0[i], this.j[i], this));
            }
        }
        return Collections.unmodifiableList(arrayList);
    }

    public String oq(String str) {
        int y = y(str);
        return y == -1 ? "" : W(this.j[y]);
    }

    public QF q(String str, @Nullable String str2) {
        BQ(this.h + 1);
        String[] strArr = this.V0;
        int i = this.h;
        strArr[i] = str;
        this.j[i] = str2;
        this.h = i + 1;
        return this;
    }

    public int size() {
        int i = 0;
        for (int i2 = 0; i2 < this.h; i2++) {
            if (!GM(this.V0[i2])) {
                i++;
            }
        }
        return i;
    }

    public boolean t(String str) {
        return y(str) != -1;
    }

    public String toString() {
        return iU();
    }

    /* renamed from: u, reason: merged with bridge method [inline-methods] */
    public QF clone() {
        try {
            QF qf = (QF) super.clone();
            qf.h = this.h;
            this.V0 = (String[]) Arrays.copyOf(this.V0, this.h);
            this.j = (String[]) Arrays.copyOf(this.j, this.h);
            return qf;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public QF w4(tF tFVar) {
        R2.u(tFVar);
        yx(tFVar.getKey(), tFVar.getValue());
        tFVar.q = this;
        return this;
    }

    int y(String str) {
        R2.u(str);
        for (int i = 0; i < this.h; i++) {
            if (str.equals(this.V0[i])) {
                return i;
            }
        }
        return -1;
    }

    public QF yx(String str, String str2) {
        R2.u(str);
        int y = y(str);
        if (y != -1) {
            this.j[y] = str2;
        } else {
            q(str, str2);
        }
        return this;
    }
}
